package be.ipl.ejb.domaine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import be.ipl.ejb.exceptions.ArgumentInvalideException;
import be.ipl.ejb.util.Util;

@Entity
@Table(name="JOUEURS", schema="STREAMS")
public class Joueur implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	@NotNull
	@Column(unique=true)
	private String pseudo;
	@NotNull
	private String password;
	@NotNull
	private String mail;
	@OneToMany(mappedBy="joueur")
	private List<Participation> participations = new ArrayList<Participation>();
	
	
	protected Joueur() {
		super();
	}


	public Joueur(String pseudo, String password, String mail) throws ArgumentInvalideException {
		super();
		Util.checkString(pseudo);
		Util.checkString(password);
		Util.checkString(mail);
		this.pseudo = pseudo;
		this.password = password;
		this.mail = mail;
	}


	public String getPseudo() {
		return pseudo;
	}

	public String getPassword() {
		return password;
	}
	
	public int getId(){
		return this.id;
	}

	public String getMail() {
		return mail;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Joueur other = (Joueur) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	public boolean chargerParticipations(){
		this.participations.size();
		return true;
	}
}
